<?php
namespace app\index\controller;

use app\common\controller\Front;
use think\Cache;

class Goods extends Front
{

    protected $store_decoration_only = false;

    /**
     * 商品列表
     *
     * @return html
     */
    public function index()
    {
        $search_key = $this->request->param('key/d', 0); // 0默认排序，1销量 ， 2人气 ，3价格
        $search_order = $this->request->param('order/d', 0); // 0是默认无排序，1是低到高，2是高到低
        $search_area_id = $this->request->param('area_id/d', 0); // 默认地区0
        $search_b_id = $this->request->param('b_id/d', 0); // 品牌ID
        $search_a_id = $this->request->param('a_id/d', 0); // 属性ID
        $search_gift = $this->request->param('gift/d', 0); // 是否有礼物
        $search_type = $this->request->param('type/d', 0); // 是否自营店铺
        $search_spec = $this->request->param('spec/a', []); // 规格查询条件
        $page_size = config('limit_goods_cate');
        $page_size = $page_size ?  : 24;
        $goods_class_array = \Fields::getById('goods_class');
        $curpage = $this->request->param('curpage/d', 1); // 当前页，默认第一页
        $tag = $this->request->param('tag/s', ''); // 商品分类标识(点击菜单来携带这个参数)
        $search_classid = $this->request->param('cate_id/s', ''); // 商品分类ID(点击排序或者分页，带这个参数)
        if (! empty($tag)) {
            foreach ($goods_class_array as $key => $val) {
                if ($val['tag'] == $tag) {
                    $search_classid = $val['id'];
                    break;
                }
                foreach ($val['_child'] as $key1 => $val1) {
                    if ($val1['tag'] == $tag) {
                        $search_classid = $val1['id'];
                        break;
                    }
                }
            }
        }
        $cache_key = 'lists_goods_cate-'
                . $search_classid . '-'
                . $search_b_id . '-'
                . $search_a_id . '-'
                . $search_key . '-'
                . $search_order . '-'
                . $search_type . '-'
                . $search_gift . '-'
                . $search_area_id . '-'
                . $curpage;
        //读取列表缓存
        $goods_common_info_list = Cache::tag('lists_goods')->get($cache_key, false);
        if($goods_common_info_list == false){
            $spec_index_cache = []; // 规格值缓存列表
            if ($search_classid > 0) {
                // 点击分类链接进来的才展示规格筛选
                $spec_list = [];
                $type_spec = [];
                $goods_class = \Fields::getById('goods_class', $search_classid);
                //数据库goods_type_spec表缓存
                $type_spec_cache = cache_read_and_write('lists_goods_type_spec', 'common/common/lists', ['goods_type_spec'], 'lists_goods', 864000);  
                if(!empty($type_spec_cache)){
                    foreach($type_spec_cache as $key => $val ){
                        if($goods_class['type_id'] == $val['type_id']){
                            $type_spec[] = $val['spec_id'];
                        }
                    }
                }
                $spec_ids = [];
                $spec_list = [];
                if (! empty($type_spec)) {
                    foreach ($type_spec as $key => $val) {
                        // 服务地区、类型和服务地市不作显示
                        if (! in_array($val, [
                            1,
                            2,
                            100
                        ])) {
                            $spec_ids[] = $val;
                        }
                    }
                }
                $all_spec_select = [];
                $spec_index_cache = cache_read_and_write('lists_goods_spec_index', 'common/common/lists', ['spec_index'], 'lists_goods', 864000);  
                foreach ($spec_ids as $key => $val) {
                    foreach ($spec_index_cache as $key1 => $val1) {
                        if ($val == $val1['sp_id']) {
                            $spec_list[$key]['index_list'][] = $val1;
                            // 初始化每个规格大项 全部选项的链接
                            if (($key_tmp = array_search($val1['sp_index_id'], $search_spec)) !== false) {
                                $tmp_spec = $search_spec;
                                unset($tmp_spec[$key_tmp]);
                                if (! empty($tmp_spec)) {
                                    $all_spec_select[$val] = implode('-', $tmp_spec);
                                } else {
                                    $all_spec_select[$val] = '';
                                }
                            }
                        }
                    }
                    if (! isset($all_spec_select[$val])) {
                        $all_spec_select[$val] = implode('-', $search_spec);
                        $spec_list[$key]['is_select'] = true; // 本规格目前选中全部
                    }
                }
            }

            $one_id = $two_id = 0;
            // 获取一级类，二级类
            if (array_key_exists($search_classid, $goods_class_array)) {
                $one_id = $search_classid;
                $one_name = $goods_class_array[$one_id]['name'];
                $one_tag = $goods_class_array[$one_id]['tag'];
                $tmp = array_keys($goods_class_array[$one_id]['_child']);
                $two_id = $tmp[0];
                $two_name = $goods_class_array[$one_id]['_child'][$two_id]['name'];
            } else {
                $two_id = $search_classid;
                foreach ($goods_class_array as $key => $val) {
                    $tmp = array_keys($val['_child']);
                    if (in_array($search_classid, $tmp)) {
                        $one_id = $val['id'];
                        $one_tag = $val['tag'];
                        $two_name = $val['_child'][$search_classid]['name'];
                        $one_name = $goods_class_array[$one_id]['name'];
                        break;
                    }
                }
            }
            $where = ' 1=1 and goods_verify=1 and goods_state=1';
            // 处理排序
            $order = 'goods_common.id desc';
            if (in_array($search_key, [
                '1',
                '2',
                '3'
            ])) {
                $sequence = $search_order == '1' ? 'asc' : 'desc';
                switch ($search_key) {
                    case '1':
                        $order = 'goods_common_static.last_30_salenum';
                        break;
                    case '2':
                        $order = 'goods_common_static.click_num';
                        break;
                    case '3':
                        $order = 'goods_common.goods_price';
                        break;
                }
                $order .= ' ' . $sequence;
            }
            // 执行正常搜索
            // 二级分类
            if ($two_id) {
                $where .= ' and gc_id=' . $two_id;
            }
            if ($search_b_id > 0) {
                $where .= ' and brand_id=' . $search_b_id;
            }
            if ($search_type == 1) {
                $where .= ' and is_own_shop=1 ';
            }
            if ($search_gift == 1) {
                $where .= ' and have_gift=1 ';
            }
            if ($search_area_id) {
                $area = rpc('common/common/one', [
                    'area',
                    [
                        'area_id' => $search_area_id
                    ],
                    [
                        'field' => 'area_name'
                    ]
                ]);
                if ($area) {
                    $search_area = $area['area_name']; // 搜索地区0
                } else {
                    $search_area = ''; // 搜索地区
                }
            }
            if (! empty($search_area) || is_array($search_spec) && ! empty($search_spec)) {
                $tmp_str = ! empty($search_area) ? '%' . $search_area . '%' : '';
                if (is_array($search_spec) && ! empty($search_spec)) {
                    foreach ($search_spec as $key => $val) {
                        $tmp_str .= $spec_index_cache[$val]['sp_index_name'] . '%'; // 搜索规格合集
                    }
                }
                $where .= ' and (goods_common.goods_name like "' . $tmp_str . '" or goods_common.goods_jingle like "' . $tmp_str . '" or goods_common.spec_value like "' . $tmp_str . '")';
            }
            // 字段
            $fields = "goods_common.id,goods_common.goods_name,goods_common.goods_jingle,goods_common.goods_jingle,goods_common.goods_jingle,goods_common.goods_image,goods_common.goods_price, "
                    ."goods_common.goods_price,goods_common.goods_unit,goods_common.store_name,goods_common.store_id,"
                    ."goods_common_static.evaluation_scores, goods_common_static.total_salenum, goods_common_static.last_30_salenum, goods_common_static.click_num";

            // 拼接sql串
            $sql = "select " . $fields . " from mall_goods_common goods_common left join mall_goods_common_static goods_common_static on goods_common.id=goods_common_static.commonid where " . $where . " order by " . $order . ' limit ' . ($curpage - 1) * $page_size . ',' . $page_size;
            ;
            $goods_common_list = rpc('common/common/sql', [
                $sql
            ]);
            $sql = "select count(goods_common.id) as num from mall_goods_common goods_common left join mall_goods_common_static goods_common_static on goods_common.id=goods_common_static.commonid where " . $where;
            $total_num = rpc('common/common/sql', [
                $sql
            ]);
            $goods_common_info_list['total_num'] = $total_num[0]['num'];
            if (! empty($goods_common_list)) {
                // 商品多图
                $commonid_array = array_map('reset', $goods_common_list); // 商品公共id数组
                $storeid_array = array(); // 店铺id数组
                $goodsid_array = array(); // 公共内容的商品代表数组
                $where = " commonid in (" . implode(',', $commonid_array) . ")";
                if (! empty($search_area) || is_array($search_spec) && ! empty($search_spec)) {
                    $tmp_str = ! empty($search_area) ? '%' . $search_area . '%' : '';
                    if (is_array($search_spec) && ! empty($search_spec)) {
                        foreach ($search_spec as $key => $val) {
                            $tmp_str .= $spec_index_cache[$val]['sp_index_name'] . '%'; // 搜索规格合集
                        }
                    }
                    $where .= ' and (goods_name like "' . $tmp_str . '" or goods_jingle like "' . $tmp_str . '" or goods_spec like "' . $tmp_str . '")';
                }
                $sql = "select id,commonid from mall_goods where " . $where . " group by commonid";
                $goodsid_tmp_array = rpc('common/common/sql', [
                    $sql
                ]);
                if (! empty($goodsid_tmp_array)) {
                    foreach ($goodsid_tmp_array as $key => $val) {
                        $goodsid_array[$val['commonid']] = $val['id'];
                    }
                }
                // 店铺
                if (! empty($goods_common_list)) {
                    foreach ($goods_common_list as $key => $val) {
                        $storeid_array[] = $val['store_id'];
                    }
                }
                $storeid_array = implode(',', array_unique($storeid_array));
                $store_list = rpc('common/common/lists', [
                    'store',
                    [
                        'id' => [
                            'in',
                            $storeid_array
                        ]
                    ],
                    [
                        'field' => 'id,name,member_id,store_domain,qq'
                    ]
                ]);
                $store_list = reset_by_key($store_list, 'id');
                foreach ($goods_common_list as $key => $value) {
                    // 店铺的开店会员编号
                    $store_id = $value['store_id'];
                    $goods_common_list[$key]['member_id'] = $store_list[$store_id]['member_id'];
                    $goods_common_list[$key]['store_domain'] = $store_list[$store_id]['store_domain'];

                    // 添加商家信息
                    $goods_common_list[$key]['qq'] = isset($store_list[$store_id]) ? $store_list[$store_id]['qq'] : '';

                    // 添加公共内容的代表商品id
                    $goods_common_list[$key]['goods_id'] = isset($goodsid_array[$value['id']]) ? $goodsid_array[$value['id']] : 0;
                }
            }
            $goods_common_info_list['one_name'] = $one_name;
            $goods_common_info_list['two_name'] = $two_name;
            $goods_common_info_list['one_id'] = $one_id;
            $goods_common_info_list['one_tag'] = $one_tag;
            $goods_common_info_list['two_id'] = $two_id;
            $goods_common_info_list['spec_list'] = $spec_listt;
            $goods_common_info_list['spec_list'] = $spec_listt;
            $goods_common_info_list['search_area'] = $search_area;
            $goods_common_info_list['list'] = $goods_common_list;
            Cache::tag('lists_goods')->set($cache_key, $goods_common_info_list, 300);
        }
        
        $query = [
            'cate_id' => $search_classid,
            'b_id' => $search_b_id,
            'a_id' => $search_a_id,
            'key' => $search_key,
            'order' => $search_order,
            'type' => $search_type,
            'gift' => $search_gift,
            'area_id' => $search_area_id,
            'curpage' => '[PAGE]'
        ];
        // 分页渲染内容
        $option = [
            'var_page' => 'curpage',
            'path' => url('index/goods/index', $query)
        ];
        $page = \Page::make($goods_common_info_list['list'], $page_size, $curpage, $goods_common_info_list['total_num'], false, $option);
        
        $this->view->assign('_page', [
            'title' => '爱员工官网',
            'name' => $two_name
        ]);
        
        // 加载地区
        $list_area = \Area::getDbData();
        $this->view->assign('list_area', json_encode($list_area));
        $this->view->assign('return_area_id', $search_area_id);
        $this->view->assign('search_area_name', $goods_common_info_list['search_area']);
        $this->view->assign('goods_class_array', $goods_class_array);
        $this->view->assign('default_classid', $search_classid);
        $this->view->assign('search_key', $search_key);
        $this->view->assign('search_order', $search_order);
        $this->view->assign('one_id', $goods_common_info_list['one_id']);
        $this->view->assign('one_tag', $goods_common_info_list['one_tag']);
        $this->view->assign('two_id', $goods_common_info_list['two_id']);
        $this->view->assign('spec_list', $goods_common_info_list['spec_list']);
        $this->view->assign('all_spec_select', $goods_common_info_list['all_spec_select']);
        $this->view->assign('search_spec', implode('-', $search_spec)); // urlShop时需要
        $this->view->assign('query_area_spec', $search_spec ? ('sp_' . implode('-sp_', $search_spec) . '/') : ''); // 地址选择时，规格是固定的 需要
        $this->view->assign('one_name', $goods_common_info_list['one_name']);
        $this->view->assign('two_name', $goods_common_info_list['two_name']);
        $this->view->assign('page', $page);
        $this->view->assign('goods_common_list', $goods_common_info_list['list']);
        $this->view->assign('total_num', $goods_common_info_list['total_num']);
        $this->view->assign('query', $query);
        return $this->view->fetch();
    }

    public function detail()
    {
        $goods_id = input('goods_id/d');
        $goods_detail = $this->getGoodsDetail($goods_id);
        $goods_info = $goods_detail['goods_info'];
        
        if (empty($goods_info)) {
            $this->error('商品不存在');
        } else {
            $buy_to_ehr = trim(config('buy_to_ehr'));
            $buy_to_ehr = $buy_to_ehr ? explode(',', $buy_to_ehr) : [];
            $gcid = $goods_info['gc_id_1'];
            if (in_array($gcid, $buy_to_ehr)) {
                $this->assign('buy_to_ehr', 1);
            }
        }
        
        $this->assign('spec_list', $goods_detail['spec_list']);
        $this->assign('spec_image', $goods_detail['spec_image']);
        $this->assign('goods_image', $goods_detail['goods_image']);
        $this->assign('goods_img1', $goods_detail['goods_image_mobile'][0]);
        $this->assign('mansong_info', $goods_detail['mansong_info']);
        $this->assign('gift_array', $goods_detail['gift_array']);
        
        $store_info = $this->getStoreOnlineInfoByID($goods_info['store_id']);
        $this->assign('store_info', $store_info);
        
        $inform_switch = true;
        // 检测商品是否下架,检查是否为店主本人
        if ($goods_info['goods_state'] != 1 || $goods_info['goods_verify'] != 1 || $goods_info['store_id'] == $this->store_id) {
            $inform_switch = false;
        }
        $this->assign('inform_switch', $inform_switch);
        
        // to do 如果使用运费模板
        
        $goods_evaluate_info = model('Common/EvaluateGoods')->getEvaluateGoodsInfoByCommonidID($goods_info['commonid']);
        $this->assign('goods_evaluate_info', $goods_evaluate_info);
        
        $this->assign('goods', $goods_info);
        
        $this->setStorePlate($goods_info);
        $this->assign('store_id', $goods_info['store_id']);
        return view('', [
            '_page' => [
                'title' => $goods_info['goods_name'],
                'name' => '爱员工官网'
            ]
        ]);
    }

    private function setStorePlate($goods_info)
    {
        // 顶部关联版式
        if ($goods_info['plateid_top'] > 0) {
            $plate_top = rpc('common/common/one', [
                'store_plate',
                [
                    'plate_id' => $goods_info['plateid_top'],
                    'store_id' => $goods_info['store_id']
                ]
            ]);
            $this->assign('plate_top', $plate_top);
        }
        
        // 底部关联版式
        if ($goods_info['plateid_bottom'] > 0) {
            $plate_top = rpc('common/common/one', [
                'store_plate',
                [
                    'plate_id' => $goods_info['plateid_bottom'],
                    'store_id' => $goods_info['store_id']
                ]
            ]);
            $this->assign('plate_bottom', $plate_bottom);
        }
    }

    /**
     * 获取店铺信息
     *
     * @param type $store_id
     * @return type
     */
    private function getStoreOnlineInfoByID($store_id)
    {
        $store_info = rpc('common/common/one', [
            'store',
            [
                'id' => $store_id
            ]
        ]);
        if (empty($store_info) || $store_info['store_state'] == '0') {
            return array();
        } else {
            $store_info['store_credit_percent'] = 100; // 默认全部５星级
            return $store_info;
        }
    }

    /**
     * 获取单条商品信息
     *
     * @param int $goods_id
     * @return array
     */
    private function getGoodsDetail($goods_id)
    {
        if ($goods_id <= 0) {
            return null;
        }
        $result1 = $this->getGoodsInfoAndPromotionById($goods_id);
        if (empty($result1)) {
            return null;
        }
        $result2 = $this->getGoodeCommonInfoByID($result1['commonid']);
        $goods_info = array_merge($result2, $result1);
        
        $goods_info['spec_value'] = unserialize($goods_info['spec_value']);
        $goods_info['spec_name'] = unserialize($goods_info['spec_name']);
        $goods_info['goods_spec'] = unserialize($goods_info['goods_spec']);
        $goods_info['goods_attr'] = unserialize($goods_info['goods_attr']);
        
        // to do 手机商品描述
        // 查询所有规格商品
        $spec_array = $this->getGoodsSpecListByCommonId($goods_info['commonid']);
        
        $count = 0;
        $spec_list = array(); // 各规格商品地址，js使用
        $spec_list_mobile = array(); // 各规格商品地址，js使用
        $spec_image = array(); // 各规格商品主图，规格颜色图片使用
        foreach ($spec_array as $key => $value) {
            $count += $value['goods_salenum'];
            $s_array = unserialize($value['goods_spec']);
            $tmp_array = array();
            if (! empty($s_array) && is_array($s_array)) {
                foreach ($s_array as $k => $v) {
                    $tmp_array[] = $k;
                }
            }
            sort($tmp_array);
            $spec_sign = implode('|', $tmp_array);
            $tpl_spec = array();
            $tpl_spec['sign'] = $spec_sign;
            $tpl_spec['url'] = url('index/goods/detail', array(
                'goods_id' => $value['goods_id']
            ));
            $spec_list[] = $tpl_spec;
            $spec_list_mobile[$spec_sign] = $value['goods_id'];
            $spec_image[$value['color_id']] = img_url($value['goods_image'], 60);
        }
        $spec_list = json_encode($spec_list);
        $goods_info['goods_salenum'] = $count;
        
        // 商品多图
        $image_more = $this->getGoodsImageByKey($goods_info['commonid'] . '|' . $goods_info['color_id']);
        $goods_image = array();
        $goods_image_mobile = array();
        
        if (! empty($image_more)) {
            foreach ($image_more as $val) {
                $goods_image[] = "{ title : '', levelA : '" . img_url($val['goods_image'], 60) . "', levelB : '" . img_url($val['goods_image'], 360) . "', levelC : '" . img_url($val['goods_image'], 360) . "', levelD : '" . img_url($val['goods_image'], 1280) . "'}";
                $goods_image_mobile[] = img_url($val['goods_image'], 360);
            }
        } else {
            $goods_image[] = "{ title : '', levelA : '" . img_url($goods_info['goods_image'], 60) . "', levelB : '" . img_url($goods_info['goods_image'], 360) . "', levelC : '" . img_url($goods_info['goods_image'], 360) . "', levelD : '" . img_url($goods_info['goods_image'], 1280) . "'}";
            $goods_image_mobile[] = img_url($goods_info['goods_image'], 360);
        }
        
        // to do 抢购
        // to do 限时折扣
        // to do 验证是否允许送赠品
        // 加入购物车按钮
        $goods_info['cart'] = true;
        
        // 虚拟、F码、预售不显示加入购物车
        if ($goods_info['is_virtual'] == 1 || $goods_info['is_fcode'] == 1 || $goods_info['is_presell'] == 1) {
            $goods_info['cart'] = false;
        }
        
        // 立即购买文字显示
        $goods_info['buynow_text'] = '立即购买';
        if ($goods_info['is_presell'] == 1) {
            $goods_info['buynow_text'] = '预售购买';
        } elseif ($goods_info['is_fcode'] == 1) {
            $goods_info['buynow_text'] = 'F码购买';
        }
        
        // to do 满即送
        $mansong_info = [];
        
        // 商品受关注次数加1, to do 缓存优化
        rpc('common/common/inc', [
            'goods',
            [
                'id' => $goods_info['goods_id']
            ],
            'goods_click',
            1
        ]);
        
        $result = array();
        $result['goods_info'] = $goods_info;
        $result['spec_list'] = $spec_list;
        $result['spec_list_mobile'] = $spec_list_mobile;
        $result['spec_image'] = $spec_image;
        $result['goods_image'] = $goods_image;
        $result['goods_image_mobile'] = $goods_image_mobile;
        $result['mansong_info'] = $mansong_info;
        $result['gift_array'] = [];
        return $result;
    }
    
    // 异步显示优惠套装/推荐组合
    public function get_bundling()
    {
        exit('');
    }
    
    // 销售记录
    public function common_salelog()
    {
        $common_id = input('common_id/d');
        $model_goods = model('Common/Goods');
        $goods_info = $model_goods->getGoodsInfo(array('commonid' => $common_id), 'group_concat(id) as goods_ids');
        if ($_GET['vr']) {
            //$model_order = Model('vr_order');
            //$sales = $model_order->getOrderAndOrderGoodsSalesRecordList(array('goods_id'=>array('in', $goods_info)), '*', 10, 'add_time desc ');
        } else {
            $model_order = model('Common/Order');
            $sales = $model_order->getOrderAndOrderGoodsSalesRecordList(array('order_goods.goods_id' => array('in', $goods_info['goods_ids'])), 'order_goods.*, order.buyer_name, order.add_time', 1, 'add_time desc');
        }

        //$this->assign('show_page', $model_order->showpage());
        $this->assign('sales', $sales);

        $this->assign('order_type', array(2 => '抢', 3 => '折', '4' => '套装'));
        return view();
    }

    // 商品公共评论
    public function common_comments()
    {
        $common_id = input('commonid/d');
        $this->_get_common_comments($common_id, input('type'), 10);
        return view();
    }

    /**
     * 商品公共评价详细页
     */
    public function common_comments_list()
    {
        return false;
    }

    private function _get_common_comments($common_id, $type, $limit)
    {
        $condition = array();
        $model_goods = model('Common/Goods');
        $goods_info = $model_goods->getGoodsInfo(array('commonid' => $common_id), 'group_concat(id) as goods_ids');
        $condition['geval_goodsid'] = array('in', $goods_info['goods_ids']);
        switch ($type) {
            case '1':
                $condition['geval_scores'] = array('in', '5,4');
                $this->assign('type', '1');
                break;
            case '2':
                $condition['geval_scores'] = array('in', '3,2');
                $this->assign('type', '2');
                break;
            case '3':
                $condition['geval_scores'] = array('in', '1');
                $this->assign('type', '3');
                break;
        }

        //查询商品评分信息
        $model_evaluate_goods = model("Common/EvaluateGoods");
        $goodsevallist = $model_evaluate_goods->getEvaluateGoodsList($condition, $limit);
        $this->assign('goodsevallist', $goodsevallist);
    }

    // 获得已加入对比的商品ID
    public function checkcompare()
    {
        return [];
    }
    
    // 添加浏览记录
    public function addbrowse()
    {}

    /**
     * 获得商品图片数组
     *
     * @param int $goods_id
     * @param array $condition
     */
    public function getGoodsImageByKey($key)
    {
        $array = explode('|', $key);
        list ($common_id, $color_id) = $array;
        return $this->db_lists('goods_images', [
            'commonid' => $common_id,
            'color_id' => $color_id
        ]);
    }

    /**
     * 取得商品详细信息（优先查询缓存）
     * 如果未找到，则缓存所有字段
     *
     * @param int $goods_commonid
     * @param string $fields 需要取得的缓存键值, 例如：'*','goods_name,store_name'
     * @return array
     */
    private function getGoodeCommonInfoByID($goods_commonid, $fields = '*')
    {
        $common_info = rpc('common/common/one', [
            'goods_common',
            [
                'id' => $goods_commonid
            ],
            [
                'field' => $fields
            ]
        ]);
        return $common_info;
    }

    /**
     * 查询商品详细信息及其促销信息
     *
     * @param int $goods_id
     * @return array
     */
    private function getGoodsInfoAndPromotionById($goods_id)
    {
        $goods_info = rpc('common/common/one', [
            'goods',
            [
                'id' => $goods_id
            ]
        ]);
        if (empty($goods_info)) {
            return array();
        }
        
        $goods_info['goods_id'] = $goods_info['id'];
        
        // to do 抢购
        $goods_info['groupbuy_info'] = [];
        
        // to do 限时折扣
        $goods_info['xianshi_info'] = [];
        
        return $goods_info;
    }

    /**
     * 获得商品规格数组
     *
     * @param unknown $common_id
     */
    private function getGoodsSpecListByCommonId($common_id)
    {
        return $this->db_lists('goods', [
            'commonid' => $common_id
        ], [
            'field' => 'id as goods_id,goods_spec,store_id,goods_image,color_id,goods_salenum'
        ]);
    }
}
